/*
 *
 * This program is free software; you can redistribute it and/or modify 
 * it under the terms of the GNU General Public License version 2 as 
 * published by the Free Software Foundation.
 *
 * thread_storage.cpp is for what ...
 *
 * Version: ***: thread_storage.cpp  Mon Aug 29 23:03:05 2011 poponion Exp $
 *
 * Authors:
 *   Author poponion <huangcm85@gmail.com>
 *     -some work detail if you want 
 *
 */

#include "thread_storage.h"

ThreadStorage::ThreadStorage()
{
  init();
}

~ThreadStorage::ThreadStorage()
{
  pthread_key_delete(&key_);
}

int ThreadStorage::init()
{
  int ret = 0;
  ret = pthread_key_create(&key_, NULL);
  if (0 != ret)
  {
    fpintf(stderr, "%s\n", "pthread_key_create failed");
  }
  return ret;
}

int ThreadStorage::set_int(int num)
{
  int ret = 0;
  void * ptr = pthread_getspecific(&key_);
  ret = *(static_cast<int*>(ptr));
  return ret;
}

int ThreadStorage::get_int(
